Skip to content

Handle implicits with default parameters. #1073

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 18, 2016
Merged

Conversation

odersky
Copy link
Contributor

@odersky odersky commented Feb 10, 2016

Fixes #576.

run/pending/Meter now compiles; crashes at runtime.

Review by @smarter.

@odersky
Copy link
Contributor Author

odersky commented Feb 10, 2016

/rebuild

@smarter
Copy link
Member

smarter commented Feb 12, 2016

The first commit in this PR was a merge commit which is confusing, I've fixed that and push-forced

acc += arg
argsOrError(pnames1, ptypes1, acc)
case ambi: AmbiguousImplicits =>
() => s"ambiguous implicits: ${ambi.explanation} of $where"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not simply return a String?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because we do not want to incur the cost of constructing it when the error does not get reported. Error strings are always lazy.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, intuitively I'd think that the cost of creating a closure would be higher than the cost of constructing a String

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Certainly not if the string is interpolated.

@smarter
Copy link
Member

smarter commented Feb 12, 2016

This doesn't work for implicit parameter lists where only some of the parameters have default values:

class A

object Impl {
  def foo()(implicit ev: Int, x: A = null): Int = 2
  def test: Int = {
    implicit val ii: Int = 1
    foo()
  }
}

stack trace: https://gist.github.com/smarter/40c990590e42be4b28f5

If an implicit parameter has a default, then that
default should be taken in case no implicit argument
is found.
@odersky
Copy link
Contributor Author

odersky commented Feb 16, 2016

Now also handles mixed lists where some implicits have defaults and others don't.

@odersky
Copy link
Contributor Author

odersky commented Feb 18, 2016

I am going to merge because I have to touch this code again for the classtags issue and I don't want to be slowed down with merging the two fixes afterwards.

odersky added a commit that referenced this pull request Feb 18, 2016
Handle implicits with default parameters.
@odersky odersky merged commit 4be70a5 into scala:master Feb 18, 2016
@allanrenucci allanrenucci deleted the fix-#576 branch December 14, 2017 19:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants